package com.ruoyi.hospital.service.operation.impl;

import java.util.ArrayList;
import java.util.List;

import ch.qos.logback.core.util.StringUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.hospital.domain.storeInfo.PharmacyDruginfo;
import com.ruoyi.hospital.mapper.storeInfo.PharmacyDruginfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hospital.mapper.operation.OperationCardMapper;
import com.ruoyi.hospital.domain.operation.OperationCard;
import com.ruoyi.hospital.service.operation.IOperationCardService;

/**
 * 首页卡片Service业务层处理
 * 
 * @author wendao
 * @date 2024-12-27
 */
@Service
public class OperationCardServiceImpl implements IOperationCardService 
{
    @Autowired
    private OperationCardMapper operationCardMapper;
    @Autowired
    private PharmacyDruginfoMapper pharmacyDruginfoMapper;
    /**
     * 查询首页卡片
     * 
     * @param id 首页卡片主键
     * @return 首页卡片
     */
    @Override
    public OperationCard selectOperationCardById(Integer id)
    {
        OperationCard card = operationCardMapper.selectOperationCardById(id);
        //查询商品列表
        List<PharmacyDruginfo> products = new ArrayList<>();
        if(!StringUtil.isNullOrEmpty(card.getDrugIds())){
            for (String s : card.getDrugIds().split(",")) {
                products.add(pharmacyDruginfoMapper.selectPharmacyDruginfoById(Integer.valueOf(s)));
            }
        }
        card.setPharmacyDruginfoList(products);
        return card;
    }

    /**
     * 查询首页卡片列表
     * 
     * @param operationCard 首页卡片
     * @return 首页卡片
     */
    @Override
    public List<OperationCard> selectOperationCardList(OperationCard operationCard)
    {
        return operationCardMapper.selectOperationCardList(operationCard);
    }

    /**
     * 新增首页卡片
     * 
     * @param operationCard 首页卡片
     * @return 结果
     */
    @Override
    public int insertOperationCard(OperationCard operationCard)
    {
        operationCard.setCreateTime(DateUtils.getNowTimeSecond());
        return operationCardMapper.insertOperationCard(operationCard);
    }

    /**
     * 修改首页卡片
     * 
     * @param operationCard 首页卡片
     * @return 结果
     */
    @Override
    public int updateOperationCard(OperationCard operationCard)
    {
        operationCard.setUpdateTime(DateUtils.getNowTimeSecond());
        return operationCardMapper.updateOperationCard(operationCard);
    }

    /**
     * 批量删除首页卡片
     * 
     * @param ids 需要删除的首页卡片主键
     * @return 结果
     */
    @Override
    public int deleteOperationCardByIds(Integer[] ids)
    {
        return operationCardMapper.deleteOperationCardByIds(ids);
    }

    /**
     * 删除首页卡片信息
     * 
     * @param id 首页卡片主键
     * @return 结果
     */
    @Override
    public int deleteOperationCardById(Integer id)
    {
        return operationCardMapper.deleteOperationCardById(id);
    }
}
